package com.lagou.worker.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @ClassName MailService
 * @Description TODO
 * @Author xsq
 * @Date 2020/7/28 17:03
 **/
@Service
public class MailService {
    @Value("${spring.mail.username}")
    private String from;
    @Autowired
    private JavaMailSender mailSender;

    /**
     * 验证码发送到邮箱
     * @param email
     * @param code
     */
    public void sendEmail(String email, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(email);
        message.setSubject("验证码");
        message.setText("您的注册验证码为【"+code+"】");
        message.setFrom(from);
        mailSender.send(message);
    }

}
